package com.yiren.dbaa.module.practice_set.carmodel.model;

import android.app.Activity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yiren.dbaa.constant.AddressConstant;
import com.yiren.dbaa.currency.api.CommonCallBack;
import com.yiren.dbaa.module.practice_set.carmodel.bean.CarBrandBean;
import com.yiren.dbaa.module.practice_set.carmodel.contract.AddCarContract;
import com.yiren.dbaa.net.OkHttpUtils;
import com.yiren.dbaa.net.bean.TestBaseBean;
import com.yiren.dbaa.net.interf.StringCallback;

import java.util.List;

/**
 * Describe
 *
 * @author WRX
 * @date 2022/12/5
 */
public class AddCarModel implements AddCarContract.Model {

    private Activity activity;
    private Gson gs;

    public AddCarModel(Activity activity) {
        this.activity = activity;
        gs = new Gson();
    }

    @Override
    public void loadAllCarBrand(CommonCallBack callBack) {
        OkHttpUtils.getInstance().getStringByAsync(activity, AddressConstant.getAllCarBrand(), new StringCallback() {
            @Override
            public void getString(String result) {
                TestBaseBean<List<CarBrandBean>> testBaseBean = gs.fromJson(result, new TypeToken<TestBaseBean<List<CarBrandBean>>>() {
                }.getType());
                callBack.success(testBaseBean.getData());
            }
        });

    }
}
